<template>
  <div class="water-environment-container">
    <!-- 查询区域 -->
    <div class="search-area">
      <el-form :inline="true" :model="searchForm" class="demo-form-inline">
        <el-form-item label="年份:">
         <el-date-picker value-format="yyyy" v-model="searchForm.mgryear" type="year" placeholder="选择年">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="水源地级别:">
          <el-select clearable v-model="searchForm.sydlevel" placeholder="选择水源地级别" style="width: 150px;">
            <el-option v-for="dict in dict.type.syd_level" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
            <!-- 这里可以根据实际数据添加选项 -->
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSearch">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="handleReset">重置</el-button>
        </el-form-item>
        <!-- <el-form-item>
          <el-button @click="handleExport">
            <i class="el-icon-download" />
            导出
          </el-button>
        </el-form-item> -->
      </el-form>
    </div>

    <!-- 表格区域 -->
    <div class="table-area">
      <el-table :data="waterEnvironmentData" style="width: 100%" border>
        <!-- 序号列 -->
        <el-table-column type="index" label="序号" width="60" align="center" />
        
        <!-- 省份 -->
        <el-table-column prop="province" label="省份" width="100" align="center" />
        
        <!-- 城市(城镇) -->
        <el-table-column prop="county" label="城市(城镇)" width="100" align="center" />
        
        <!-- 水源地环境护状况综合评估得分 -->
        <el-table-column prop="swes" label="水源地环境护状况综合评估得分SWES" width="180" align="center" />
        
        <!-- 综合评估结果 -->
        <el-table-column prop="swesResult" label="综合评估结果" width="100" align="center" />
        
        <!-- 取水量保证状况分值 -->
        <el-table-column prop="wg" label="取水量保证状况分值WG" width="120" align="center" />
        
        <!-- 水源达标状况分值 -->
        <el-table-column prop="sq" label="水源达标状况分值SQ" width="120" align="center" />
        
        <!-- 管理状况分值 -->
        <el-table-column prop="ms" label="管理状况分值MS" width="120" align="center" />
        
        <!-- 保护区建设状况 -->
        <el-table-column label="保护区建设状况" align="center">
          <el-table-column prop="hfScore" label="保护区划分分值" width="120" align="center" />
          <el-table-column prop="bzScore" label="保护区标志设置分值" width="120" align="center" />
          <el-table-column prop="glScore" label="一级保护区隔离防护分值" width="140" align="center" />
        </el-table-column>
        
        <!-- 监控能力值 -->
        <el-table-column prop="jkScore" label="监控能力值" width="100" align="center" />
        
        <!-- 保护区整治状况 -->
        <el-table-column label="保护区整治状况" align="center">
          <el-table-column prop="pcr1" label="一级保护区整治分值" width="120" align="center" />
          <el-table-column prop="pcr2" label="二级保护区整治分值" width="120" align="center" />
          <el-table-column prop="pcqr" label="准保护区整治分值" width="120" align="center" />
        </el-table-column>
        
        <!-- 风险防控能力分值 -->
        <el-table-column prop="fxfkScore" label="风险防控能力分值" width="120" align="center" />
        
        <!-- 应急能力分值 -->
        <el-table-column prop="yjScore" label="应急能力分值" width="100" align="center" />
        
        <!-- 管理措施分值 -->
        <el-table-column prop="glcScore" label="管理措施分值" width="100" align="center" />
      </el-table>
      
      <!-- 分页区域 -->
      <div class="pagination-area">
        <el-pagination
          background
          :current-page="pageNum"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { getScoreDrinkSource } from "./api.js"
export default {
  name: 'WaterEnvironment',
  dicts: ["syd_level"],
  data() {
    return {
      // 查询表单
      searchForm: {
        mgryear: '2025',
        sydlevel: ''
      },
      // 水源地环境数据
      waterEnvironmentData: [
        
      ],
      // 分页参数
      pageNum: 1,
      pageSize: 10,
      total: 0
    }
  },
  mounted() {
    this.handleSearch()
  },
  methods: {
    // 处理查询
    handleSearch() {
      // 实际应用中这里应该调用API获取数据
      getScoreDrinkSource({...this.searchForm, pageNum: this.pageNum, pageSize: this.pageSize}).then(res => {
        if (res.code == 200) {
          this.waterEnvironmentData = res.data
          this.total = res.total
        }
      })
      
    },
    
    // 处理重置
    handleReset() {
      this.searchForm = {
        mgryear: '2025',
        sydlevel: ''
      }
      this.pageNum = 1
      this.pageSize = 10
      this.handleSearch()
    },
    
    // 处理导出
    handleExport() {
      // 实际应用中这里应该调用导出API
      this.$message.success('数据导出成功')
    },
    
    // 分页大小变化时触发
    handleSizeChange(val) {
      this.pageSize = val
      this.handleSearch()
    },
    
    // 当前页码变化时触发
    handleCurrentChange(val) {
      this.pageNum = val
      this.handleSearch()
    }
  }
}
</script>

<style scoped>
.water-environment-container {
  padding: 20px;
}

.search-area {
  margin-bottom: 20px;
}

.table-area {
  background: #fff;
  padding: 10px;
  border-radius: 4px;
  overflow-x: auto;
}

.pagination-area {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>